package com.wjbgn.bsolver.server.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjbgn.bsolver.server.dto.BugAnsweredRecordDTO;
import com.wjbgn.bsolver.server.entity.BugAnsweredRecordDO;
import com.wjbgn.stater.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 
 * Create Date: 2022-04-21T13:26:52.898
 * @author wjbgn
 * @version 1.0
 */
@Component
public class BugAnsweredRecordDoConvert {

    /**
     * DtoToDo
     *
     * @param bugAnsweredRecordDTO
     * @return
     */
    public static BugAnsweredRecordDO dtoToDo(BugAnsweredRecordDTO bugAnsweredRecordDTO) {
            BugAnsweredRecordDO bugAnsweredRecordDO = new BugAnsweredRecordDO();
        BeanCopierUtil.copy(bugAnsweredRecordDTO, bugAnsweredRecordDO);
        return bugAnsweredRecordDO;
    }

    /**
     * DoToDto
     *
     * @param bugAnsweredRecordDO
     * @return
     */
    public static BugAnsweredRecordDTO doToDto(BugAnsweredRecordDO bugAnsweredRecordDO) {
            BugAnsweredRecordDTO bugAnsweredRecordDTO = new BugAnsweredRecordDTO();
        BeanCopierUtil.copy(bugAnsweredRecordDO, bugAnsweredRecordDTO);
        return bugAnsweredRecordDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<BugAnsweredRecordDTO> pageConvert(Page<BugAnsweredRecordDO> pageDO) {
        List<BugAnsweredRecordDTO> list = listConvert(pageDO.getRecords());
        Page<BugAnsweredRecordDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<BugAnsweredRecordDTO> listConvert(List<BugAnsweredRecordDO> listDO) {
        List<BugAnsweredRecordDTO> list = new ArrayList<>();
            BugAnsweredRecordDTO bugAnsweredRecordDTO;
        for (BugAnsweredRecordDO bugAnsweredRecordDO : listDO) {
                bugAnsweredRecordDTO = new BugAnsweredRecordDTO();
            BeanCopierUtil.copy(bugAnsweredRecordDO, bugAnsweredRecordDTO);
            list.add(bugAnsweredRecordDTO);
        }
        return list;
    }
}